{* FILTERS *}

<script language="javascript">

	function updateRequest(id,action) {ldelim}
		var forma = document.getElementById("list_form");
		forma.op.value=action;
		forma.id.value=id;
		forma.submit();
	{rdelim}

	function startEdit(id,team,start,end,tsk) {ldelim}
		var forma = document.getElementById("task_form");
		forma.id.value=id;
		forma.op.value='edit';
		forma.teamid.value=team;
		forma.task.value=tsk;
		forma.startdate.value = start;
		forma.enddate.value = end;
		document.getElementById("edit_form").style.display = '';
		document.getElementById("add_form").style.display = 'none';
	{rdelim}

	function cancelEdit() {ldelim}
		var forma = document.getElementById("task_form");
		forma.op.value='add';
		forma.id.value='';
		forma.teamid.value='0';
		forma.task.value='';
		forma.startdate.value='';
		forma.enddate.value='';
		document.getElementById("edit_form").style.display = 'none';
		document.getElementById("add_form").style.display = '';
	{rdelim}

	function validate(form) {ldelim}
		var forma = document.getElementById(form);
		var valid=true;

		var el = getDateFromString(forma.startdate.value,'{$dateformat}');
		var desde=new Date();
		desde.setFullYear(el.year,el.month,el.day);
		//desde.setHours(el.hour);
		//desde.setMinutes(el.minute);

		el = getDateFromString(forma.enddate.value,'{$dateformat}');
		var hasta=new Date();
		hasta.setFullYear(el.year,el.month,el.day);
		//hasta.setHours(el.hour);
		//hasta.setMinutes(el.minute);		

		if (hasta<desde) {ldelim}
			valid=false;
			alert('{$lang.invaliddate}');
		{rdelim} else if (forma.task.value=='') {ldelim}
			valid=false;
			alert('{$lang.messagemissing}');
		{rdelim}
		if (valid) processForm(form);
	
	{rdelim}
	
	function deleteItem() {ldelim}
		if (confirm('{$lang.confirmdelete}')) {ldelim} 
			updateRequest('','remove')
		{rdelim}	
	{rdelim}
</script>

<center>
{if $CURRENT_USER->groupid eq 'ADMIN' or $CURRENT_USER->groupid eq 'COORD'} 
<form method="post" id="task_form">
	<input type="hidden" name="flowid" id="flowid" value="{$flowid}">
	<input type="hidden" name="action" id="action" value="taskadmin">
	<input type="hidden" name="op" id="op" value="add">
	<input type="hidden" name="id" id="id" value="">	
	 <table width="100%" cellpadding="0" cellspacing="0">
	   {if $CURRENT_USER->groupid eq 'ADMIN'}
		   <tr>
			 <td>&nbsp;{$lang.team}</td>
			 <td>
				<select name="teamid" id="teamid" class="txt">
					<option value="0">{$lang.everyone}</option>
					{foreach from=$teamlist item=op}
						<option value="{$op->id}">{$op->name}</option>
					{/foreach}
				</select>			 
			</tr>
	   {else}
			<input type="hidden" name="teamid" id="teamid" value="{$CURRENT_USER->teamid}">	   
	   {/if}
	   <tr>
		 <td>&nbsp;{$lang.startdate}</td>
		 <td>
		 	<input type="text" size="20" readonly name="startdate" id="startdate" class="txt">
		 	<img style="position:absolute" src="images/calendar.png" alt="Calendar" width="24" height="24" onclick="displayCalendar(document.forms['task_form'].startdate,'{$dateformat}',this,false,false,'{$CURRENT_USER->lang}')">
		 </td>
		</tr>
	   <tr>
		 <td>&nbsp;{$lang.enddate}</td>
		 <td>
	 		<input type="text" size="20" readonly name="enddate" id="enddate" class="txt">
			<img style="position:absolute" src="images/calendar.png" alt="Calendar" width="24" height="24" onclick="displayCalendar(document.forms['task_form'].enddate,'{$dateformat}',this,false,false,'{$CURRENT_USER->lang}')">
		 </td>
		</tr>		
	   <tr>
		 <td valign="top">&nbsp;{$lang.task}</td>
		 <td>
		 	<input type="text" size="50" maxlength="255" name="task" id="task" class="txt">
		 </td>
		</tr>
			 <td align="right" colspan="2">
			 <div id="add_form">
			 {include file="button.tpl" name=$lang.new action="validate('task_form')"}
			 </div>
			 <div id="edit_form" style="display: none;">
			 {include file="button.tpl" name=$lang.ok action="validate('task_form')"}
			 &nbsp;{include file="button.tpl" name=$lang.cancel action="cancelEdit()"}
			 </div>
			 </td>
	   </tr>
	 </table>	
</form>
</center>
{/if}

<center>

<form method="post" id="list_form">
	<input type="hidden" name="flowid" id="flowid" value="{$flowid}">
	<input type="hidden" name="action" id="action" value="taskadmin">
	<input type="hidden" name="op" id="op" value="">	
	<input type="hidden" name="id" id="id" value="">
<table align="center" width="100%" border="0" cellpadding="0" cellspacing="0">

	<thead>
		<tr>
			<th>{$lang.team}</th>
			<th>{$lang.startdate}</th>
			<th>{$lang.enddate}</th>
			<th>{$lang.task}</th>
			<th>{$lang.status}</th>
			{if $CURRENT_USER->groupid eq 'ADMIN' or $CURRENT_USER->groupid eq 'COORD'}
			<th>&nbsp;</th>
			<th>
				<img src="images/arrowdown.png" alt="" width="18" height="18" class="link" onclick="checkAll('itemid[]')">
				<img src="images/arrowup.png" alt="" width="18" height="18" class="link" onclick="uncheckAll('itemid[]')">
			</th>
			{/if}
		</tr>
	</thead>

	{* TABLE BODY - DYNAMIC *}
	<tbody>
		{assign var="rowclass" value="uneven"}
		{foreach from=$list item=row}
			{eval var=$row->status() assign="stid"}
			<tr class="{$rowclass}" {if $stid eq 'tskstarted'} style="font-weight: bold" {elseif $stid eq 'tskfinished'} style="font-style: italic" {/if}>
				{if $row->teamid eq 0 }
					<td>{$lang.everyone}</td>
				{else}
					<td>{$row->team->name}</td>
				{/if}
				<td>{$row->startdatef($CURRENT_USER->timezone)}</td>
				<td>{$row->enddatef($CURRENT_USER->timezone)}</td>
				<td>{$row->task}</td>				
				<td>{$lang.$stid}</td>
				{if $CURRENT_USER->groupid eq 'ADMIN' or ($CURRENT_USER->groupid eq 'COORD' AND $row->teamid eq $CURRENT_USER->teamid)}
				<td>				
					<span onclick="startEdit('{$row->id}','{$row->teamid}','{$row->startdatef($CURRENT_USER->timezone)}','{$row->enddatef($CURRENT_USER->timezone)}','{$row->task}')" class="link">{$lang.edit}</span>
				</td>
				<td align="center">
					<input type="checkbox" class="txt" name="itemid[]" id="itemid[]" value="{$row->id}" />
				</td>
				{elseif $CURRENT_USER->groupid eq 'COORD'}
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				{/if} 
			</tr>
			{if $rowclass eq 'even'}
				{assign var="rowclass" value="uneven"}
			{else}
				{assign var="rowclass" value="even"}
			{/if}				
		{/foreach}

	</tbody>
	
	{if $CURRENT_USER->groupid eq 'ADMIN' or $CURRENT_USER->groupid eq 'COORD'}
	<tfoot>
		<tr>
			<th colspan="7">
				{include file="button.tpl" name=$lang.remove action="deleteItem()"}
			</th>
		</tr>
	</tfoot>
	{/if}
</table>
</form>
<center>

